$(document).ready(function(){
	App.init();
	$("#btn_save").click(function(){
		save();
	});
	$('[name="newPassword"]').click(function(){
		var  submitData=getParams("content_container");
		var password=submitData["newPassword"];
		checkPassword(password);
	});
	$('[name="newPassword"]').on("keyup",function(){
		var  submitData=getParams("content_container");
		var password=submitData["newPassword"];
		checkPassword(password);
		$("#newPasswordPopover").show();
	});
	$('[name="newPassword"]').on("blur",function(){
		var  submitData=getParams("content_container");
		var password=submitData["newPassword"];
		if(checkPassword(password)){
		$("#newPasswordPopover").hide();
		}
	});
	$('[name="confirmNewPassword"]').on("keyup",function(){
		var submitData=getParams("content_container");
		if(submitData["confirmNewPassword"]!=submitData["newPassword"]){
			$("#confirmNewPasswordPopvoer").show();
		}else{
			$("#confirmNewPasswordPopvoer").hide();
		}
	});
});


function showAlertModal(title,content){
	$("#alertModal").find('h4').html(title);
	$("#alertModal").find('p').html(content);
	$("#alertModal").modal('show');
}
function save(){
var submitData=getParams("content_container");
var password=submitData["newPassword"];
if(checkPassword(password)==false){
	$("#newPasswordPopover").show();
	return;
}

if(submitData["confirmNewPassword"]!=submitData["newPassword"]){
	$("#confirmNewPasswordPopvoer").show();
	return;
}else{
	$("#confirmNewPasswordPopvoer").hide();
}
$.ajax( {
		url :'core/user/updatePasswordForExpired.htm',
		type : 'post',
		dataType:'json',
		data:submitData,
		success : function(result) {
			showAlertModal('注意',result.message);
			if(result.status==3){
				$("#password").val(submitData["confirmNewPassword"]);
				$("#loginForm").submit();
			}
	     },error: function(XMLHttpRequest, textStatus, errorThrown){
            showAlertModal('注意','系统异常！'+errorThrown);
     }
	});
}

function getParams(containerId){
	var submitData={};
	$("#"+containerId+" input[type='password']").each(function(){
		submitData[$(this).attr("name")]=$(this).val();
	});
	$("#"+containerId+" input[type='text']").each(function(){
		submitData[$(this).attr("name")]=$(this).val();
	});
	return submitData;
}

